﻿@using Masuit.MyBlogs.Domain.Entity
@using Masuit.MyBlogs.Domain.Enum
@using Masuit.MyBlogs.Services.DTO
@using Masuit.Tools.Helper
@using Masuit.Tools
@model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
<div class="col-md-9 box-left">
    <div class="wrapper-content  animated fadeIn blog">
        @if (Model.Posts.Data.Any())
        {
            <div class="orderby">
                <div class="row">
                    <div class="col-md-10 text-center">
                        @{ await Html.RenderPartialAsync("_Pagination", Model.PageParams); }
                    </div>
                    <div class="col-md-2">
                        <div class="btn-group pull-right">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                排序方式<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="@Context.Request.Path">最后修改日期</a>
                                </li>
                                <li>
                                    <a href="@Context.Request.Path?orderby=0">最后发表日期</a>
                                </li>
                                <li role="separator" class="divider"></li>
                                <li>
                                    <a href="@Context.Request.Path?orderby=3">评论最多</a>
                                </li>
                                <li>
                                    <a href="@Context.Request.Path?orderby=2">访问量最多</a>
                                </li>
                                <li>
                                    <a href="@Context.Request.Path?orderby=4">支持最多</a>
                                </li>
                                <li>
                                    <a href="@Context.Request.Path?orderby=5">最热门</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            var rnd = new Random().Next(Model.Posts.CurrentCount > 2 ? 2 : 0, Model.Posts.CurrentCount);
            for (var index = 0; index < Model.Posts.CurrentCount; index++)
            {
                if (rnd == index && Model.ListAdvertisement != null)
                {
                    await Html.RenderPartialAsync("_ArticleListAdvertisement", Model.ListAdvertisement);
                }

                var post = Model.Posts.Data[index];
                await Html.RenderPartialAsync("_ArticleListItem", post);
            }
        }
        else
        {
            var list = Model.PostsQueryable.OrderBy(p => Guid.NewGuid()).Skip(0).Take(5).ToList();
            if (list.Any())
            {
                <div class="page-header">
                    <h3>Oops！抱歉~没有找到相关的文章或资源！如果您有相关的结果，您可以 <a asp-controller="Post" asp-action="Publish" class="btn btn-info btn-lg">点击这里</a> 投稿哦！以下是一些随机推荐：</h3>
                </div>
                foreach (PostDto post in list)
                {
                    await Html.RenderPartialAsync("_ArticleListItem", post);
                }
            }
        }
        <div class="col-md-12 text-center">
            @{ await Html.RenderPartialAsync("_Pagination", Model.PageParams); }
        </div>
    </div>
</div>